package Ctr;

import DB.ConnectionDB;
import DB.CustomerDB;
import Model.Customer;
import java.util.ArrayList;

public class CustomerCtr {
    private ConnectionDB connection;
    private CustomerDB customerDB;

    public CustomerCtr() {
        customerDB = new CustomerDB();
    }

    //Insert Customer
    public void insertCustomer(int id,String name,String address, int zipCode,int phoneNo){
        Customer customer = new Customer(id,name,address,zipCode,customerDB.getZipCodeCity(zipCode),phoneNo);

        try {
            connection.startTransaction();
            CustomerDB customerDB = new CustomerDB();
            customerDB.insertCustomer(customer);
            connection.commitTransaction();
        }
        catch (Exception e) {
            connection.rollbackTransaction();
        }

    }

    // Find a Customer
    public Customer findCustomer(int id){
        return customerDB.findCustomer(id);
    }


    //Find All Customer
    public ArrayList<Customer> getAllCustomers(boolean retrieveAssociation){
        return customerDB.getAllCustomers(false);
    }

    //Update Customer
    public void updateCustomer(int id){
        customerDB.updateCustomer(customerDB.findCustomer(id));

    }

    //Delete Customer
    public void deleteCustomer(int id){
        customerDB.deleteCustomer(id);
    }

    //Get max
    public int getMaxId() {
        int id = customerDB.customerGetMax();
        return id;
    }
}
